package com.ruoyi.bizsys.controller;

import java.util.List;

import com.ruoyi.common.annotation.RepeatSubmit;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.bizsys.domain.AwardDistributionRatio;
import com.ruoyi.bizsys.service.IAwardDistributionRatioService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 奖励分销比Controller
 *
 * @author african-loan
 * @date 2022-06-24
 */
@RestController
@RequestMapping("/bizsys/ratio")
public class AwardDistributionRatioController extends BaseController {
    @Autowired
    private IAwardDistributionRatioService awardDistributionRatioService;

    /**
     * 查询奖励分销比列表
     */
    @PreAuthorize("@ss.hasPermi('bizsys:ratio:list')")
    @GetMapping("/list")
    public TableDataInfo list(AwardDistributionRatio awardDistributionRatio) {
        startPage();
        List<AwardDistributionRatio> list = awardDistributionRatioService.selectAwardDistributionRatioList(awardDistributionRatio);
        return getDataTable(list);
    }

    /**
     * 导出奖励分销比列表
     */
    @PreAuthorize("@ss.hasPermi('bizsys:ratio:export')")
    @Log(title = "奖励分销比", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(AwardDistributionRatio awardDistributionRatio) {
        List<AwardDistributionRatio> list = awardDistributionRatioService.selectAwardDistributionRatioList(awardDistributionRatio);
        ExcelUtil<AwardDistributionRatio> util = new ExcelUtil<AwardDistributionRatio>(AwardDistributionRatio.class);
        return util.exportExcel(list, "ratio");
    }

    /**
     * 获取奖励分销比详细信息
     */
    @PreAuthorize("@ss.hasPermi('bizsys:ratio:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(awardDistributionRatioService.selectAwardDistributionRatioById(id));
    }

    /**
     * 新增奖励分销比
     */
    @RepeatSubmit
    @PreAuthorize("@ss.hasPermi('bizsys:ratio:add')")
    @Log(title = "奖励分销比", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AwardDistributionRatio awardDistributionRatio) {
        return toAjax(awardDistributionRatioService.insertAwardDistributionRatio(awardDistributionRatio));
    }

    /**
     * 修改奖励分销比
     */
    @PreAuthorize("@ss.hasPermi('bizsys:ratio:edit')")
    @Log(title = "奖励分销比", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AwardDistributionRatio awardDistributionRatio) {
        return toAjax(awardDistributionRatioService.updateAwardDistributionRatio(awardDistributionRatio));
    }

    /**
     * 删除奖励分销比
     */
    @PreAuthorize("@ss.hasPermi('bizsys:ratio:remove')")
    @Log(title = "奖励分销比", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(awardDistributionRatioService.deleteAwardDistributionRatioByIds(ids));
    }
}
